<template>
    <el-container class="home-container">
        <el-header>
            <div>应急指挥平台</div>
            <el-button type="info" @click="loginOut">退出</el-button>
        </el-header>
        <el-container>
            <el-aside :width="isCollapse ? '64px' : '200px'">
                <div class="toggle-button" @click="toggleBtn">|||</div>
                <el-menu
                    background-color="#333744"
                    text-color="#fff"
                    active-text-color="#409eff"
                    :collapse="isCollapse"
                    :collapse-transition="false"
                    unique-opened
                    router
                    :default-active="activePath">
                    <template v-for="item in menuList">
                        <el-submenu v-if="item.children" :index="item.id + ''" :key="item.id">
                            <template slot="title">
                                <i class="el-icon-location"></i>
                                <span>{{item.authName}}</span>
                            </template>
                            <el-menu-item :index="'/'+subItem.path" v-for="subItem in item.children" :key="subItem.id" @click="saveNavState('/'+subItem.path)">
                                <template slot="title">
                                    <i class="el-icon-menu"></i>
                                    <span>{{subItem.authName}}</span>
                                </template>
                            </el-menu-item>
                        </el-submenu>
                        <el-menu-item v-else :index="'/'+item.path + ''" :key="item.id" @click="saveNavState('/'+item.path)">
                                <i class="el-icon-location"></i>
                                <span slot="title">{{item.authName}}</span>
                        </el-menu-item>
                    </template>
                </el-menu>
            </el-aside>
            <el-main>
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>
<script>
export default {
  data () {
    return {
      isCollapse: true,
      activePath: '',
      menuList: [
        {
          id: 103,
          authName: '危险源',
          path: 'dangerList'
        },
        {
          id: 104,
          authName: '防护目标',
          path: 'helpsure',
          children: [
            {
              id: 1033,
              authName: '测试',
              path: 'users'
            },
            {
              id: 1034,
              authName: '测试',
              path: 'test'
            }
          ]
        },
        {
          id: 105,
          authName: '应急队伍',
          path: 'dug'
        },
        {
          id: 106,
          authName: '医疗机构',
          path: 'doctor',
          children: [
            {
              id: 1036,
              authName: '测试',
              path: 'test'
            }
          ]
        }
      ]
    }
  },
  created () {
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  methods: {
    loginOut () {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    toggleBtn () {
      this.isCollapse = !this.isCollapse
    },
    saveNavState (activePath) {
      window.sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
    }
  }
}
</script>
<style lang="less" scoped>
.home-container {
    height:100%
}

.el-header {
    background-color: #373d41;
    display:flex;
    justify-content: space-between;
    align-items: center;
    color:#fff;
    font-size:20px;
    >div {
        display:flex;
        align-items: center
    }
}

.el-aside {
    background-color: #333744;
    .el-menu {
        border-right: none
    }
}

.el-main {
    background-color: #eaedf1
}

.toggle-button {
    background-color: #4a5064;
    font-size:10px;
    line-height: 24px;
    color:#fff;
    text-align: center;
    cursor: pointer;
    letter-spacing: 0.2em;
}
</style>
